﻿/// <reference path="../../lib/google-maps-3-vs-1-0.js" />
app.controllers.Directions = new Ext.Controller({


    //Requires LatLng Object for to and from. Requires TravelMode string.
    getTimeToLocation: function (options) {

        var directionsService = new google.maps.DirectionsService();

        var toLatLng = options.toLatLng;
        var fromLatLng = options.fromLatLng;
        var request = { origin: fromLatLng, destination: toLatLng, travelMode: "DRIVING" };
        directionsService.route(request, function (response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                options.record.distance = response.routes[0].legs[0].distance.value;
                options.record.leaveTime = response.routes[0].legs[0].duration.value.toString();
            }
        });

    },


    getLatLngOfAddress: function (options) {
        console.log('Hello');
        var geocoder = new google.maps.Geocoder();
        var address = options.address;
        geocoder.geocode({ 'address': address }, function (results, status) {

            if (status == google.maps.GeocoderStatus.OK) {
                //Insert code for storing LatLng to profile
            }
            else {
                alert("Geocode was not successful because: " + status);
            }

        });

    }

});